mini.parse();
var form = new mini.Form("form1");
var auditEmp = mini.get('auditEmp');

//弹出错误提示
function updateError(e) {

    console.log(e);
    var id=e.sender.name+"_error";
    var el=document.getElementById(id);
    console.log(e.errorText);
    console.log( el.innerHTML);

    if(el){
        el.innerHTML=e.errorText;
    }
}
function onPwdValidation(e) {

    console.log(e);
    updateError(e);
}

//确定按钮
function onSave() {
    // 校验
    form.validate();
    if (form.isValid() == false) return;
    var aaa = form.getData();
    aaa = JSON.stringify(aaa);
    $.ajax({
        url: "http://localhost:8080/DSMP/driverinfo/saveDriverInfos.do",
        contentType: "application/json",
        type: "post",
        data: aaa,
        success: function (data) {//请求成功完成后要执行的方法
            mini.alert(data.msg)
            closeWindow("save")
        },
        error: function (data) {
            mini.alert(cuole);
        }
    })
}

// 接收父页面传过来的值的方法
function SetData(data) {
    data = mini.clone(data);       //将父页面传过来的值深克隆一下
    console.log(data.row);
    if (data.action == "edit") {      //当状态是edit的时候
        var id = data.row.driverInfoId        //打点调用你获取要用的ID参数下面换成正确额得接口调用
        console.log(id);
        $.ajax({
            url: "http://localhost:8080/DSMP/driverinfo/getOne.do?id="+id,
            contentType: "application/json",
            type: "post",
            success: function (data) {//请求成功完成后要执行的方法
                console.log(data);
                form.setData(data.obj);     //form用setData得到数据添加到框里
            },
            error: function (data) {
                mini.alert(cuole);
            }
         })
    } else if (data.action == "new") {

    }
}

//关闭页面的方法
function closeWindow(action) {
    if (window.CloseOwnerWindow)
        return window.CloseOwnerWindow(action);
    else
        window.close();
}

function onOk() {
    onSave();
    grid.reload();
}

//点击取消按钮时
function onCancel() {
    closeWindow("cancel");
}

function GetData() {
    mini.parse();
    var form = new mini.Form("form1");
    var o = form.getData();         //form用getData能获取到子页面上的数据
    return o;                       //返回数据
}


function onButtonEdit() {
    mini.open({
        targetWindow: window,
        url: "Departmentlist.html",
        title: "关联用户账号",
        height: 700,
        width: 800,
        showMaxButton: true,
        showModal: Boolean,
        allowResize: Boolean,
        setReadOnly: false,
        onload: function () {

        },
        ondestroy: function (action) {

            var iframe = this.getIFrameEl();
            var data = iframe.contentWindow.GetData();
            data = mini.clone(data);    //必须
            console.log(data, '子页面传来的')
            if (data.length > 0) {
                var ids = [];
                var names = [];
                for (var i = 0, l = data.length; i < l; i++) {
                    var r = data[i];
                    ids.push(r.PersonnelFiles_id);
                    names.push(r.PersonnelFiles_OperatorName);
                }
                var id = ids.join(',');
                var nameText = names.join(',');
                auditEmp.setValue(id);
                auditEmp.setText(nameText);
            } else {
                mini.alert("请选中一条记录");
            }

        }

    })
}